/*=================================页面事件============================================================*/
//页面的load方法
function loadNews(){
	findNewsByID(this.opener.newsID);
}

/*=================================数据读取============================================================*/

//根据newsID查到对应的新闻记录
function findNewsByID(newsID){
	if(bXmlHttpSupport) {
    	var sUrl = 'findNewsContentByID.action';
    	var params = "newsID=" + newsID;
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
            	var oRequest = eval('(' + request.responseText + ')');
            	//alert(request.responseText);
            	var news = oRequest.news;
            	putNewsIntoPage(news);
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(params);
    }
}

//将查到的新闻的各个字段放入对应的位置
function putNewsIntoPage(news){
	newsTitle.innerHTML = news.title;
	if (news.content == null){
		newsContent.document.body.innerHTML = "";
	}else{
		newsContent.document.body.innerHTML = news.content;
	}
}

//提交新闻正文的修改
function modifyNewsContent(){
	if(bXmlHttpSupport) {
    	var sUrl = 'modifyNewsContent.action';
    	//alert(newsContent.document.body.innerHTML);
    	var params = "newsContent=" + encodeURIComponent(newsContent.document.body.innerHTML);
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
            	var oRequest = eval('(' + request.responseText + ')');
            	//alert(request.responseText);
            	document.getElementById("returnMsg").innerHTML = oRequest.result;
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(params);
    }
}
